home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / window3a / palette3.frm < prev    next >
Text File  |  1999-09-23  |  4KB  |  149 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Windows Colours by oigres P"
  4.    ClientHeight    =   4155
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6375
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   277
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   425
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.PictureBox Picture1 
  14.       AutoRedraw      =   -1  'True
  15.       AutoSize        =   -1  'True
  16.       Height          =   3855
  17.       Left            =   2400
  18.       ScaleHeight     =   253
  19.       ScaleMode       =   3  'Pixel
  20.       ScaleWidth      =   45
  21.       TabIndex        =   4
  22.       Top             =   120
  23.       Width           =   735
  24.    End
  25.    Begin VB.CommandButton Command5 
  26.       Caption         =   "Randomize Element"
  27.       Height          =   495
  28.       Left            =   0
  29.       TabIndex        =   3
  30.       Top             =   720
  31.       Width           =   1095
  32.    End
  33.    Begin VB.ListBox List1 
  34.       Height          =   2790
  35.       Left            =   3480
  36.       TabIndex        =   2
  37.       Top             =   120
  38.       Width           =   2655
  39.    End
  40.    Begin VB.CommandButton Command3 
  41.       Caption         =   "Restore"
  42.       Height          =   495
  43.       Left            =   0
  44.       TabIndex        =   1
  45.       Top             =   1320
  46.       Width           =   1095
  47.    End
  48.    Begin VB.CommandButton Command1 
  49.       Caption         =   "Randomize All Colours"
  50.       Height          =   495
  51.       Left            =   0
  52.       TabIndex        =   0
  53.       Top             =   120
  54.       Width           =   1095
  55.    End
  56. End
  57. Attribute VB_Name = "Form1"
  58. Attribute VB_GlobalNameSpace = False
  59. Attribute VB_Creatable = False
  60. Attribute VB_PredeclaredId = True
  61. Attribute VB_Exposed = False
  62. 'Windows Colours by oigres P
  63. 'Email: oigres@postmaster.co.uk
  64. '
  65. 'Adapted from MSDN :indented by indenter5
  66. Const COLOR_BACKGROUND = 1
  67. Const COLOR_ACTIVECAPTION = 2
  68. Const COLOR_WINDOWFRAME = 6
  69. Const clr As Integer = 255
  70. Dim SavedColors(clr) As Long
  71.  
  72. Sub Command1_Click()
  73.     Dim i As Long
  74.     ' Change all display elements:
  75.     ReDim NewColors(clr) As Long
  76.     ReDim IndexArray(clr) As Long
  77.     For i = 0 To clr
  78.         NewColors(i) = QBColor(Int(16 * Rnd))
  79.         IndexArray(i) = i
  80.     Next i
  81.     SetSysColors clr + 1, IndexArray(0), NewColors(0)
  82.  
  83. End Sub
  84.  
  85. Private Sub Command3_Click()
  86.     Dim i As Long
  87.     ' Restore system colors:
  88.     ReDim IndexArray(clr) As Long
  89.     For i = 0 To clr
  90.         IndexArray(i) = i
  91.     Next i
  92.  
  93.     SetSysColors clr + 1, IndexArray(0), SavedColors(0)
  94.     picupdate
  95. End Sub
  96.  
  97. Private Sub Command5_Click()
  98.     If List1.ListIndex > -1 Then
  99.         SetSystemPaletteUse Form1.hdc, SYSPAL_NOSTATIC
  100.         mydc = GetDC(Form1.hwnd)
  101.         oldmode = SetBkMode(mydc, TRANSPARENT)
  102.         SetSysColors 1, List1.ListIndex, QBColor(Int(16 * Rnd))
  103.         SetBkMode mydc, oldmode
  104.         ReleaseDC Form1.hwnd, mydc
  105.         SetSystemPaletteUse Form1.hdc, SYSPAL_STATIC
  106.         picupdate
  107.     End If
  108. End Sub
  109.  
  110. Sub Form_Load()
  111.     Dim i As Long
  112.  
  113.     ' Save current system colors:
  114.     For i = 0 To clr
  115.         SavedColors(i) = GetSysColor(i)
  116.         List1.AddItem i & ":" & Hex(SavedColors(i))
  117.     Next i
  118.  
  119.     Show
  120.     picupdate 'draw colours into picbox
  121.     
  122. End Sub
  123. Sub picupdate()
  124.     'set up pic display
  125.     Picture1.CurrentX = 0
  126.     Picture1.CurrentY = 0
  127.     i = 0
  128.     For Y = 0 To Picture1.ScaleHeight Step Picture1.ScaleHeight \ 24
  129.         Picture1.CurrentX = 0
  130.         Picture1.CurrentY = Y
  131.         Picture1.Print i
  132.         Picture1.Line (18, Y)-(Picture1.ScaleWidth, Y + 8), GetSysColor(i), BF
  133.         i = i + 1
  134.     Next
  135.  
  136. End Sub
  137.  
  138. Private Sub Form_Unload(Cancel As Integer)
  139.     'set colours back to original then exit program correctly
  140.     'if you don't unload form then colours not restored
  141.     Command3.Value = True
  142.     Unload Me
  143.     Set Form1 = Nothing
  144. End Sub
  145.  
  146. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  147.     Picture1.ToolTipText = Hex(Picture1.Point(X, Y))
  148. End Sub
  149.